#include <bits/stdc++.h>
// 2025/02/01
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m, presum[100001][2], cnt[100001][2], color[100001], num[100001];

signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> num[i], num[i] %= 10007;
    for (int i = 1; i <= n; i++)
    {
        cin >> color[i];
        cnt[color[i]][i % 2]++;
        presum[color[i]][i % 2] += num[i];
        presum[color[i]][i % 2] %= 10007;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        int c = color[i], p = i % 2;
        ans += i % 10007 * (presum[c][p] + (cnt[c][p] - 2) * num[i] % 10007 + 10007) % 10007;
        ans %= 10007;
    }
    cout << ans;
    return 0;
}